import http from '@/utils/http'
import VueCookies from 'vue-cookies'

const apiKey = '195a9b99ea7a0d259151b5c412bb631b'
let sign
if (process.env.NODE_ENV === 'production') {
  // sign = localStorage.getItem('wx_sign')
  sign = VueCookies.get('wx_sign')
} else {
  sign = '06f5bc6e309f5ad027420d05cef35c1f'
}

let uploadFileKey = 'Gn1xVdBiTClSSHKZifg0pTQSU5XGagWO'
let apiList = {
  getOssSign:
    'http://hfc.suoluomei.com/diagnose/public/index.php?s=/admin/photo/getOssAccessKeySecret'
}

let nowTime = new Date()
let nowYear = nowTime.getFullYear()
let nowMonth = nowTime.getMonth() + 1
let nowDay = nowTime.getDate()
let nowHour = nowTime.getHours()
let nowMinute = nowTime.getMinutes()
// fixed 修复日期的bug 格式必须为 '2019-xx-xx' ,'2019-1-3' 报错
const nowDate = `${nowYear}-${nowMonth < 10 ? '0' + nowMonth : nowMonth}-${
  nowDay < 10 ? '0' + nowDay : nowDay
}`

const ossThumb = '?x-oss-process=image/quality,Q_70'
const ossLarge = '?x-oss-process=image/quality,Q_100'

/**
 * @msg: 封装默认请求参数
 * @param {Object}
 * @return:
 */
const post = (url, data = {}) =>
  http.post(
    url,
    Object.assign(
      {
        api_key: apiKey,
        sign
      },
      data
    )
  ).then(response => response.data)

// 首页菜单
const getNavigationList = data => post('getNavigationList', data)

// 首页banner
const getBannerList = data => post('getBannerList', data)

// 首页列表
const getHomeList = data => post('getHomeList', data)

// 我的收藏
const getCollectorListByUser = data => post('getCollectorListByUser', data)

// 已购课程
const getLatelyData = data => post('getLatelyData', data)

// 我的
const getUserInfo = data => post('getUserInfo', data)

// 推广用户信息
const getSpreadDataByUser = data => post('getSpreadDataByUser', data)

// 推广商品列表
const getSpreadVideoList = data => post('getSpreadVideoList', data)

// 累计用户
const getSpreadUserList = data => post('getSpreadUserList', data)

// 推广订单列表
const getSpreadOrderList = data => post('getSpreadOrderList', data)

// 账户明细
const getDrawingList = data => post('getDrawingList', data)

// 账户余额
const getUserBalance = data => post('getUserBalance', data)

// 视频列表
const getVideoListByType = data => post('getVideoListByType', data)

// 专栏详情
const getVideoInfo = data => post('getVideoInfo', data)

// 学习记录
const playVideoLog = data => post('playVideoLog', data)

// 收藏与取消收藏
const operateVideoByType = data => post('operateVideoByType', data)

// 优惠券
const getCouponList = data => post('getCouponList', data)

// 首页推荐优惠券
const getHomeCoupon = data => post('getHomeCoupon', data)

// 领取优惠券
const getCoupon = data => post('getCoupon', data)

// 搜索
const getVideoListByKeyword = data => post('getVideoListByKeyword', data)

// 搜索历史
const getSearchHistory = data => post('getSearchHistory', data)

// 删除历史记录
const deleteSearch = data => post('deleteSearch', data)

// 二维码
const getPublicAddress = data => post('getPublicAddress', data)

// 推广海报
const getInvitationPosters = data => post('getInvitationPosters', data)

// 推广记录
const saveUserInvitation = data => post('saveUserInvitation', data)

// 生成订单支付
const processOrder = data => post('processOrder', data)

// 提现
const extractWallet = data => post('extractWallet', data)


export {
  getNavigationList,
  getBannerList,
  getHomeList,
  getCollectorListByUser,
  getLatelyData,
  getSpreadUserList,
  getSpreadVideoList,
  getSpreadDataByUser,
  getVideoListByType,
  getVideoInfo,
  getCouponList,
  getUserInfo,
  getVideoListByKeyword,
  operateVideoByType,
  getSpreadOrderList,
  getDrawingList,
  getUserBalance,
  getSearchHistory,
  deleteSearch,
  getCoupon,
  getHomeCoupon,
  getPublicAddress,
  getInvitationPosters,
  processOrder,
  saveUserInvitation,
  extractWallet,
  playVideoLog
}
